package com.codemart.lanze.modules.sys.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codemart.lanze.modules.sys.mapper.UserRoleMapper;
import com.codemart.lanze.modules.sys.model.UserRole;

/**
 * @description:
 * @author: lanze
 */
@Transactional
@Service
public class UserRoleService extends ServiceImpl<UserRoleMapper, UserRole> {

	@Transactional(readOnly = true)
	public UserRole findByUserIdAndRoleId(Long userId, Long roleId) {

		QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
		if (userId != null) {
			queryWrapper.eq("user_id", userId);
		}
		if (roleId != null) {
			queryWrapper.eq("role_id", roleId);
		}

		return this.getOne(queryWrapper);
	}
}
